package com.automannn.atm_back.codegenerate.util;

import java.io.File;

/**
 * 辅助删除文件
 * @author chenkh
 * @time 2020/6/27 15:01
 */
public class DeleteFileUtil {
    private static String T;
    private static final String U;
    private static final String V;
    private static final String W = "action";
    private static final String X = "entity";
    private static final String Y = "page";
    private static final String Z = "service";
    private static final String aa = "impl";
    private static String ab;
    private static String ac;
    private static String ad;
    private static String ae;
    private static String af;
    private static String ag;
    private static String ah;
    private static String ai;

    public DeleteFileUtil() {
    }

    public static void init(String gn_package, String name) {
        ab = U + "/" + "action" + "/" + gn_package + "/" + name + "Action.java";
        ac = U + "/" + "entity" + "/" + gn_package + "/" + name + "Entity.java";
        ad = U + "/" + "page" + "/" + gn_package + "/" + name + "Page.java";
        ae = U + "/" + "service" + "/" + gn_package + "/" + name + "ServiceI.java";
        af = U + "/" + "service" + "/" + "impl" + "/" + gn_package + "/" + name + "ServiceImpl.java";
        ag = V + "/" + gn_package + "/" + name + ".jsp";
        ah = V + "/" + gn_package + "/" + name + "-main-add.jsp";
        ai = V + "/" + gn_package + "/" + name + "-main-edit.jsp";
        String path = getProjectPath();
        ab = path + "/" + ab;
        ac = path + "/" + ac;
        ad = path + "/" + ad;
        ae = path + "/" + ae;
        af = path + "/" + af;
        ag = path + "/" + ag;
        ah = path + "/" + ah;
        ai = path + "/" + ai;
    }

    public static void main(String[] args) {
        String name = "Company";
        String subPackage = "test";
        j(subPackage, name);
    }

    public static void j(String subPackage, String codeName) {
        init(subPackage, codeName);
        l(ab);
        l(ac);
        l(ad);
        l(ae);
        l(af);
        l(ai);
        l(ag);
        l(ah);
        System.out.println("--------------------删除动作结束-----------------------");
    }

    public static String getProjectPath() {
        String path = System.getProperty("user.dir").replace("\\", "/") + "/";
        return path;
    }

    public static boolean l(String strFileName) {
        File fileDelete = new File(strFileName);
        if (fileDelete.exists() && fileDelete.isFile()) {
            System.out.println("--------成功删除文件---------" + strFileName);
            return fileDelete.delete();
        } else {
            return false;
        }
    }

    static {
        T = CodeResourceUtil.bussiPackage;
        U = "src/" + T;
        V = "WebRoot/" + T;
    }
}
